/**
 *     tipple is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    tipple is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with tipple.  If not, see <http://www.gnu.org/licenses/>.
 * Copyright 2009 James Osler, Adam Tomkins

 */



package v0_4;

//~--- JDK imports ------------------------------------------------------------

import java.io.*;

import java.util.*;

//import java.lang.String;
public class readFile {
    static List<Beer> beerList = new ArrayList<Beer>();

    /**
     * public static void main (String[] args) {
     *
     *   String[] result = "testing:1:2:3".split(":");
     *   for (int x=0; x<result.length; x++) {
     *       System.out.println(result[x]);
     *   }
     * }
     */
    public static List<Beer> fInput(String fLoc) {
        File                file = new File(fLoc);
        FileInputStream     fis  = null;
        BufferedInputStream bis  = null;
        DataInputStream     dis  = null;

        try {
            fis = new FileInputStream(file);

            // Here BufferedInputStream is added for fast reading.
            bis = new BufferedInputStream(fis);
            dis = new DataInputStream(bis);

            // dis.available() returns 0 if the file does not have more lines.
            while (dis.available() != 0) {

                // this statement reads the line from the file and print it to
                // the console.
                read(dis.readLine());
            }

            // dispose all the resources after using them.
            fis.close();
            bis.close();
            dis.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return beerList;
    }

    public static void read(String s) {
        String[] result  = s.split("-");
        int      id      = Integer.parseInt(result[0]);
        double   percent = Double.parseDouble(result[2]);
        int      volume  = Integer.parseInt(result[3]);
        double   cost    = Double.parseDouble(result[4]);

        beerList.add(new Beer(id, result[1], percent, volume, cost));
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
